package com.kejiguan.ui.presenter;

import android.content.Context;
import android.widget.Toast;

import com.android.volley.error.VolleyError;
import com.android.volley.response.Response;
import com.kejiguan.ui.request.GsonRequest;
import com.kejiguan.ui.request.RequestUtil;
import com.kejiguan.ui.response.NeItemRunDataResponse;
import com.kejiguan.ui.util.CommonDate;
import com.kejiguan.ui.util.DateFormatUtil;

import org.greenrobot.eventbus.EventBus;

import java.text.ParseException;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by YYY on 2016/4/28.
 */
public class NeItemRunDataPresenter extends BaseFragmentPresenter{


    public void getNeItemRunData(final Context context, final String displayName, final String displayId)
    {

        long currentTime=System.currentTimeMillis();
        String currentDate=String.valueOf(currentTime);
        try {
            currentDate= DateFormatUtil.longToString(currentTime, "yyyyMMdd");
        } catch (ParseException e) {
            e.printStackTrace();
        }


        Map<String,String> params=new HashMap<>();
        params.put("requestCode","704");
        params.put("messageId",currentDate+"S"+currentTime);
        params.put("systemCode", CommonDate.SystemCode);
//        params.put("packageNo",displayId);




        final GsonRequest<NeItemRunDataResponse> request = new GsonRequest("getNeRunData", NeItemRunDataResponse.class, new Response.Listener<NeItemRunDataResponse>() {
            @Override
            public void onResponse(NeItemRunDataResponse response) {

                if (response.getRetCode().equals("0000"))
                {
                    response.setDisplayId(displayId);
                    response.setDisplayName(displayName);
                    response.rebuidDatas();
                    EventBus.getDefault().post(response);
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {

            }
        });

        RequestUtil.sendRequest(context, params, request);
    }

}
